package com.steven.ourcontest.contest.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.steven.ourcontest.R
import com.steven.ourcontest.app.AppRouter
import com.steven.ourcontest.contest.bean.MatchInfo
import com.steven.ourcontest.utils.DateUtil

class ContestHistoryAdapter(private val context: Context) :
    RecyclerView.Adapter<HistoryViewHolder>() {
    val listData by lazy {
        ArrayList<MatchInfo>()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryViewHolder {
        val inflater = LayoutInflater.from(context).inflate(R.layout.item_match_history, parent, false)
        return HistoryViewHolder(inflater)
    }

    override fun getItemCount(): Int {
        return listData.size
    }

    override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) {
        val itemData = listData[position]
        holder.apply {
            tv_match_name?.text = itemData.name
            itemView.setOnClickListener {
                AppRouter.openMatchDetailActivity(context, itemData.id)
            }
        }
    }
}

class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    val tv_match_name: TextView? = itemView.findViewById(R.id.tv_match_name)
}
